package com.tengju.data.infrastructure.repository.clickhouse.crm;

import com.tengju.data.domain.model.clickhouse.CrmSecAnalysisMRepository;
import com.tengju.data.domain.model.clickhouse.CrmSecAnalysisM;
import com.tengju.data.domain.shared.Month;
import com.tengju.data.infrastructure.persistence.mybatis.dataobject.CrmSecAnalysisMDO;
import com.tengju.data.infrastructure.persistence.mybatis.mapper.clickhouse.crm.CRMSecAnalysisMapper;
import com.tengju.data.infrastructure.repository.clickhouse.convert.CrmSecAnalysisConvert;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.util.CollectionUtils;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author chenhang
 * @Date 2021/3/6
 */
@Repository
@Slf4j
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
public class CrmSecAnalysisMRepositoryImpl implements CrmSecAnalysisMRepository {

    private final CRMSecAnalysisMapper crmSecAnalysisMMapper;


    @Override
    public List<CrmSecAnalysisM> listSecAnalysis(Long clubId, String td, String ytd, String ymtd, Month curMonth) {
        List<CrmSecAnalysisMDO> crmSecAnalysisMDOS = crmSecAnalysisMMapper.listSecAnalysis(clubId,td,ytd,ymtd,curMonth.getMonthInt());
        if (CollectionUtils.isEmpty(crmSecAnalysisMDOS)) {
            return Collections.emptyList();
        }
        return crmSecAnalysisMDOS.stream()
                .map(CrmSecAnalysisConvert::toModel)
                .collect(Collectors.toList());
    }
}
